/**
 * Created by bin.zhang on 14-11-10.
 */
define(['jquery','underscore','backbone','global','text!/android_asset/busAppWeb/module/busApp/busLine/busLineResult.html'],
    function($,_,Backbone,global,html){
        var busLineResultView = Backbone.View.extend({
            template: _.template(html),
            initialize:function(data){
                this.render();
            },
            render:function(){
                $('div#contentID').html(this.template);
                $('body').trigger("create");
            },
            searchBusLine:function(condition){
                var busLine = new BMap.BusLineSearch(global.city);
                var busSiteList = [];
                var busSite = [];
                busLine.setGetBusLineCompleteCallback(function(results){
                    if(results != null){
                        for(var i =0; i < results.getNumBusStations(); i++ ){
                            busSite[results.name] += "<p>"+ results.getBusStation(i).name+"</p>";
                        }
                        busSiteList.push(busSite[results.name] + "</div>")
                        $('#busLineResult').innerHTML = busSiteList.join('</br>') ;
                        $('#busLineResult').html(busSiteList);
                        $('#busLineResult').trigger("create");
                    }
                });

                busLine.setGetBusListCompleteCallback(function (results){
                    if(results.getNumBusList() > 0){
                        busSite = [];
                        for(var i = 0; i < results.getNumBusList(); i ++){
                            var divString = "<div data-role='collapsible'>";
                            divString += "<h3>" + results.getBusListItem(i).name+"</h3>"
                            busSite[results.getBusListItem(i).name] = divString;
                            busLine.getBusLine(results.getBusListItem(i));
                        }
                    }
                })
                busLine.getBusList(condition);
            }
        });
        return busLineResultView;

    }
)